package main 

import (
	"fmt"
)

func getSum(n1 int,n2 int) int{
	return n1+n2
}
//传递函数参数  当作函数指针就可以了
func myFunc(funcvar func(n1 int,n2 int) int,a int,b int) int{
	return funcvar(a,b)
}
//给函数类型给别名
type myFuncType func(n1 int,n2 int)int
func myFunc2(funcvar myFuncType,a int,b int) int{
	return funcvar(a,b)
}
//返回返回值命名
func myFunc3(n1 int,n2 int)(sum int,sub int){
	sum=n1+n2
	sub=n1-n2
	//return sum,sub
	return
}

func myFunc4(n1 int,args...int)int{
	sum:=n1

	for i:=0;i<len(args);i++{
		sum+=args[0]
	}
	return sum
}
func main(){

	a:=getSum
	fmt.Printf("a type=%T,getSum type=%T\n",a,getSum)


	res:=a(100,200)
	fmt.Println(res)

	res = myFunc(getSum,100,100)
	fmt.Println(res)

	fmt.Println("***********************")

	//给类型起别中
	type myInt int
	var x myInt
	x = 10
	var y int 
	//y = x //类型不一样
	y = int(x)
	fmt.Printf("x=%v,y=%v\n",x,y)

	

	res = myFunc2(getSum,1,1)
	fmt.Println("res=",res)

	sum,sub:= myFunc3(1,2)
	fmt.Printf("sum=%v,sub=%v\n",sum,sub)

	res = myFunc4(10,20,30,40)
	fmt.Printf("res=%v\n",res)

}